/*
 * @Author: xiaoyan
 * @Date: 2021-11-19 09:52:43
 * @LastEditors: xiaoyan
 * @LastEditTime: 2021-11-26 17:23:15
 * @Description: router
 * @FilePath: \user_auth_front\src\router\index.tsx
 */
import { Routes, Route, Navigate } from "react-router-dom";
import { getToken } from '@/utils/storage'

import Layout from "@/layout"
import Home from "@/pages/home";
import Login from "@/pages/login";
import NotFound from "@/pages/notFound";

import Organization from "@/pages/organization"
import User from "@/pages/user"
import Role from "@/pages/role"
import Application from "@/pages/application"
import Menu from "@/pages/menu"

export default function routes(){
  return (
    <Routes>
        <Route path="" element={<Test />} >
            <Route path="" element={<Home />}></Route>
            <Route path="/home" element={<Home />}></Route>
            <Route path="/organization" element={<Organization />}></Route>
            <Route path="/user" element={<User />}></Route>
            <Route path="/role" element={<Role />}></Route>
            <Route path="/application" element={<Application />}></Route>
            <Route path="/menu" element={<Menu />}></Route>
        </Route>
        <Route path="/login" element={<Login />} />
        <Route path="*" element={<NotFound />} />
    </Routes>
  );
};

function Test() {
  return getToken() ? <Layout /> : <Navigate to="/login" />;
}
